package com.leslie.hhcommunity.util;

import com.leslie.hhcommunity.entity.User;
import org.springframework.stereotype.Component;

/**
 * @author
 * @PackageName:com.leslie.hhcommunity.util
 * @ClassnName:HostHolder
 * @Description: 持有用户信息，用于代替session对象,避免多线程产生的冲突
 * @Date 2022/1/2  18:41
 */
@Component
public class HostHolder {

	private ThreadLocal<User> users = new ThreadLocal<>();

	public void setUser(User user) {
		users.set(user);
	}

	public User getUser() {
		return users.get();
	}

	public void clear() {
		users.remove();
	}
}
